package com.liaogui.算法题;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @author liaogui
 * @date 2025/3/28 11:38
 */
public class 删除有序数组中的重复项 {
    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        int length = removeDuplicates(nums);
        System.out.println(length);
    }

    public static int removeDuplicates(int[] nums) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != nums[index]) {
                ++index;
                nums[index] = nums[i];
            }
        }
        return index + 1;
    }
}
